package com.web;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

/**
 * @author zhang guoxiang
 * @date 2023/7/12
 */
public class SocketConnect {


    public static void main(String[] args) throws IOException, InterruptedException {
        ServerSocket serverSocket = new ServerSocket(9000);
        Socket socket = serverSocket.accept();
        if (socket != null) {
            System.out.println("获取到连接");
            OutputStream outputStream = socket.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
            for (; ; ) {
                System.out.println("发送数据");
//                TimeUnit.SECONDS.sleep(1);
                long l = System.currentTimeMillis();
                bufferedWriter.write(l + "test" + "\n");
                bufferedWriter.flush();
            }
        }

    }
}
